#include "UdpServer.hpp"
#include "Dictionary.hpp"

// ./udpserver localport
int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        std::cerr<<"Usage: "<<argv[0]<<"localport"<<std::endl;
        Die(USAGE_ERR);
    }

    uint16_t port=std::atoi(argv[1]);
    ENABLE_CONSOLE_LOG();
    std::shared_ptr<Dictionary> dict_sptr=std::make_shared<Dictionary>();

    // std::unique_ptr<Udpserver> svr_ptr=std::make_unique<Udpserver>(port);
    std::unique_ptr<Udpserver> svr_ptr=std::make_unique<Udpserver>([&dict_sptr](const std::string& word){
        return dict_sptr->Translate(word);
    },port);

    //还可以这样写
    // func_t f=std::bind(&Dictionary::Translate,dict_sptr.get(),std::placeholders::_1);
    // std::unique_ptr<Udpserver> svr_ptr2=std::make_unique<Udpserver>(f,port);


    svr_ptr->InitServer();
    svr_ptr->Start();

    return 0;
}